home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / shopdrop.swf / scripts / __Packages / PackageHandler.as < prev    next >
Text File  |  2007-09-27  |  6KB  |  191 lines

  1. class PackageHandler
  2. {
  3.    static var ySpeed = 100;
  4.    var nPack = 5;
  5.    var cPack = 0;
  6.    var bGiftCard = false;
  7.    var baseTime = 5;
  8.    var nBonusRange = 10;
  9.    var cBonusTime = 0;
  10.    var baseBalanceTime = 15;
  11.    var nBalanceRange = 20;
  12.    var cBalanceTime = 0;
  13.    function PackageHandler(loc, mcVanishing)
  14.    {
  15.       this.location = loc;
  16.       this.oHandler = new smashing.ClipHandler(loc,2);
  17.       this.vanishing = mcVanishing;
  18.       var _loc3_ = loc._parent.mcPackageLeft;
  19.       var _loc5_ = loc._parent.mcPackageRight;
  20.       this.startY = _loc3_._y;
  21.       this.range = _loc5_._x - _loc3_._x;
  22.       this.startX = _loc3_._x;
  23.       if(_global.bBonusCard == true || _global.bBalance == true)
  24.       {
  25.          this.update = this.updateCards;
  26.          this.makeBonusTime();
  27.          this.makeBalanceTime();
  28.       }
  29.       else
  30.       {
  31.          this.update = this.updateNormal;
  32.       }
  33.    }
  34.    function updateNormal(nElapsed)
  35.    {
  36.       this.cPack += nElapsed;
  37.       if(this.cPack >= this.nPack)
  38.       {
  39.          this.cPack %= this.nPack;
  40.          this.addPackage();
  41.       }
  42.       var _loc4_ = this.oHandler.clips;
  43.       var _loc5_ = _loc4_.length;
  44.       var _loc3_ = undefined;
  45.       var _loc2_ = 0;
  46.       while(_loc2_ < _loc5_)
  47.       {
  48.          _loc3_ = _loc4_[_loc2_];
  49.          if(_loc3_ != null)
  50.          {
  51.             _loc3_.update(nElapsed);
  52.          }
  53.          _loc2_ = _loc2_ + 1;
  54.       }
  55.    }
  56.    function updateCards(nElapsed)
  57.    {
  58.       this.cPack += nElapsed;
  59.       if(this.cPack >= this.nPack)
  60.       {
  61.          this.cPack %= this.nPack;
  62.          this.addPackage();
  63.       }
  64.       this.cBonusTime += nElapsed;
  65.       if(this.cBonusTime >= this.nBonusTime)
  66.       {
  67.          this.cBonusTime = 0;
  68.          this.makeBonusTime();
  69.          this.addBonusCard();
  70.       }
  71.       this.cBalanceTime += nElapsed;
  72.       if(this.cBalanceTime >= this.nBalanceTime)
  73.       {
  74.          this.cBalanceTime = 0;
  75.          this.makeBalanceTime();
  76.          this.addBalanceIcon();
  77.       }
  78.       var _loc4_ = this.oHandler.clips;
  79.       var _loc6_ = _loc4_.length;
  80.       var _loc3_ = undefined;
  81.       var _loc2_ = 0;
  82.       while(_loc2_ < _loc6_)
  83.       {
  84.          _loc3_ = _loc4_[_loc2_];
  85.          if(_loc3_ != null)
  86.          {
  87.             _loc3_.update(nElapsed);
  88.          }
  89.          _loc2_ = _loc2_ + 1;
  90.       }
  91.    }
  92.    function addPackage()
  93.    {
  94.       var _loc2_ = this.oHandler.addClip("mcPickup");
  95.       _loc2_._y = this.startY;
  96.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  97.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  98.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  99.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  100.       _loc2_.direction.normalizeMe();
  101.       _loc2_.lastY = _loc2_._y;
  102.       _loc2_.vanishing = this.vanishing;
  103.       if(this.bGiftCard == true)
  104.       {
  105.          _loc2_.toGiftCard();
  106.       }
  107.       else
  108.       {
  109.          _loc2_.a.pickup.gotoAndStop(Math.ceil(Math.random() * 5));
  110.       }
  111.    }
  112.    function addBonusCard()
  113.    {
  114.       var _loc2_ = this.oHandler.addClip("mcPickup");
  115.       _loc2_._y = this.startY;
  116.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  117.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  118.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  119.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  120.       _loc2_.direction.normalizeMe();
  121.       _loc2_.lastY = _loc2_._y;
  122.       _loc2_.vanishing = this.vanishing;
  123.       _loc2_.toBonusCard();
  124.    }
  125.    function addBalanceIcon()
  126.    {
  127.       var _loc2_ = this.oHandler.addClip("mcPickup");
  128.       _loc2_._y = this.startY;
  129.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  130.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  131.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  132.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  133.       _loc2_.direction.normalizeMe();
  134.       _loc2_.lastY = _loc2_._y;
  135.       _loc2_.vanishing = this.vanishing;
  136.       _loc2_.toBalanceIcon();
  137.    }
  138.    function reset()
  139.    {
  140.       this.cPack = 0;
  141.       this.oHandler.removeAllClips();
  142.       this.toPackages();
  143.    }
  144.    function toGiftCards()
  145.    {
  146.       this.bGiftCard = true;
  147.       var _loc4_ = this.oHandler.clips;
  148.       var _loc3_ = undefined;
  149.       var _loc2_ = 0;
  150.       while(_loc2_ < _loc4_.length)
  151.       {
  152.          _loc3_ = _loc4_[_loc2_];
  153.          if(_loc3_ != null)
  154.          {
  155.             if(_loc3_.nType == GrabPackage.NORMAL)
  156.             {
  157.                _loc3_.toGiftCard();
  158.             }
  159.          }
  160.          _loc2_ = _loc2_ + 1;
  161.       }
  162.    }
  163.    function toPackages()
  164.    {
  165.       this.bGiftCard = false;
  166.       var _loc4_ = this.oHandler.clips;
  167.       var _loc3_ = undefined;
  168.       var _loc2_ = 0;
  169.       while(_loc2_ < _loc4_.length)
  170.       {
  171.          _loc3_ = _loc4_[_loc2_];
  172.          if(_loc3_ != null)
  173.          {
  174.             if(_loc3_.nType == GrabPackage.NORMAL)
  175.             {
  176.                _loc3_.toPackage();
  177.             }
  178.          }
  179.          _loc2_ = _loc2_ + 1;
  180.       }
  181.    }
  182.    function makeBonusTime()
  183.    {
  184.       this.nBonusTime = this.baseTime + Math.floor(Math.random() * this.nBonusRange);
  185.    }
  186.    function makeBalanceTime()
  187.    {
  188.       this.nBalanceTime = this.baseBalanceTime + Math.floor(Math.random() * this.nBalanceRange);
  189.    }
  190. }
  191.